home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJLSR111.ZIP / libsrc / c / io / fgets.c < prev    next >
C/C++ Source or Header  |  1993-06-28  |  642b  |  32 lines

  1. /* This is file FGETS.C */
  2. /* This file may have been modified by DJ Delorie (Jan 1991).  If so,
  3. ** these modifications are Coyright (C) 1993 DJ Delorie, 24 Kirsten Ave,
  4. ** Rochester NH, 03867-2954, USA.
  5. */
  6.  
  7. #if defined(LIBC_SCCS) && !defined(lint)
  8. static char sccsid[] = "@(#)fgets.c    5.2 (Berkeley) 3/9/86";
  9. #endif LIBC_SCCS and not lint
  10.  
  11. #include    <stdio.h>
  12.  
  13. char *
  14. fgets(s, n, iop)
  15. char *s;
  16. register FILE *iop;
  17. {
  18.     register c;
  19.     register char *cs;
  20.  
  21.     cs = s;
  22.     while (--n>0 && (c = getc(iop)) != EOF) {
  23.         *cs++ = c;
  24.         if (c=='\n')
  25.             break;
  26.     }
  27.     if (c == EOF && cs==s)
  28.         return(NULL);
  29.     *cs++ = '\0';
  30.     return(s);
  31. }
  32.